package com.jial08.designpatterns.prototype.shallow;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>类描述：浅复制。</p>
 *
 * @author jl
 * @version v1.0.0.1。
 * @since JDK1.8。
 * <p>创建日期：2019/10/26 下午6:11。</p>
 */
public class Demo {
	public static void main(String[] args) {
		Address0 address = new Address0();
		address.setAdd("杭州");
		List<String> list = new ArrayList<>();
		list.add("1");
		list.add("2");
		Student0 student1 = new Student0();
		student1.setAge(10);
		student1.setAddress(address);
		student1.setBirthday(new Date());
		student1.setGrade(1);
		student1.setList(list);
		Student0 student2 = student1.clone();
		System.out.println("原始类：" + student1.toString());
		System.out.println("复制类：" + student2.toString());
		System.out.println();
		address.setAdd("洛阳");
		student2.setBirthday(null);
		student2.setGrade(2);
		List<String> list1 = student2.getList();
		list1.add("3");
		student2.setList(list1);
		System.out.println("原始类改变地址：" + student1.toString());
		System.out.println("复制改变类：" + student2.toString());
	}
}
